package com.aube.interact.model;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huyaonan on 16/3/23.
 */
public class GoodsListModel extends BaseModel {

    public List<GoodsModel> data;

    public static GoodsListModel parse(String s) {
        GoodsListModel response = new GoodsListModel();
        try {
            JSONObject jsonObject = new JSONObject(s);
            JSONArray jsonArray = jsonObject.optJSONArray("data");
            List<GoodsModel> goodsModels = new ArrayList<>();
            if(goodsModels != null) {
                for(int i=0; i<jsonArray.length(); i++)
                    goodsModels.add(GoodsModel.parse(jsonArray.optJSONObject(i)));
            }
            response.data = goodsModels;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }

}
